import { get, post } from '../ajax'
import { getAjaxBaseUrl } from '../handler'

const baseUrl = getAjaxBaseUrl('/gateway', '/energy')

/** 新增网关 */
export function addGateway(params: any) {
  return post(`${baseUrl}/add`, params)
}

/** 绑定计量器具 */
export function bindMeteringDevice(params: any) {
  return post(`${baseUrl}/bindTools`, params)
}

/** 删除计量器具绑定 */
export function delBindMeteringDevice(gatewayToolsId: number) {
  return get(`${baseUrl}/delBindTools`, { gatewayToolsId })
}

/** 删除网关 */
export function deleteGateway(id: number) {
  return get(`${baseUrl}/delete`, { id })
}

/** 导出网关信息 */
export function exportGatewayInfo() {
  return post(`${baseUrl}/exportGateway`)
}

/** 获取统计数据 */
export function getStatisticsData() {
  return get(`${baseUrl}/getStatisticalData`)
}

/** 分页获取计量器具 */
export function loadMeteringDeviceListByPage(
  pageNum: number = 1,
  pageSize: number = 10,
  gatewayId?: number,
  pointId?: number,
  queryText?: string,
) {
  return get(`${baseUrl}/getToolsPage`, {
    gatewayId,
    pointId,
    pageNum,
    pageSize,
    queryText,
  })
}

/** 分页查询网关信息 */
export function loadGatewayListByPage(pageNumber: number = 1, pageSize: number = 10, params: any = {}) {
  return get(`${baseUrl}/page`, {
    pageNum: pageNumber,
    pageSize,
    ...params,
  })
}
/** 修改网关 */
export function updateGateway(params: any) {
  return post(`${baseUrl}/update`, params)
}

/** 根据网关查询其绑定的计量器具 */
export function queryTools(gatewayId: number) {
  return get(`${baseUrl}/getTools`, { gatewayId })
}

/** 分页查询网关测点 */
export function loadIndicatorsByGatewayPage(
  gatewayId: number,
  pageNum: number = 1,
  pageSize: number = 10,
  toolsId?: number,
) {
  return get(`${baseUrl}/getIndicatorPage`, {
    gatewayId,
    pageNum,
    pageSize,
    toolsId,
  })
}
